package com.lb.activity.mapper;

import com.lb.activity.po.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author liubin
 */
public interface PermissionMapper extends Mapper<Permission> {
    /**
     * 获取角色下所有的权限的id
     * @param roleId
     * @return
     */
    @Select("select PERMISSIONID from role_permission where ROLEID = #{roleId}")
    List<Long> listMenuIdByRoleId(@Param("roleId") Long roleId);

    /**
     * 删除
     * @param roleId
     */
    @Delete(" delete from role_permission \n" +
            "    where roleid = #{roleId,jdbcType=DECIMAL}")
    void removeByRoleId(Long roleId);

    @Select("select distinct sap.id , sap.parentid, sap.name, sap.url,sap.percode,sap.type,sap.icon,sap.sort \n" +
            "\t\tfrom permission sap\n" +
            "\t\tleft join role_permission srp on sap.id = srp.permissionid \n" +
            "\t\tleft join role sar on sar.id =  srp.roleid\n" +
            "\t\tleft join user_role sur on sur.roleid=sar.id\n" +
            "\t\tleft join user sau on sau.id=sur.userid where sau.id = #{id}\n" +
            "\t\tand sap.status = 0\n" +
            "\t\torder by sap.sort asc")
    List<Permission> listMenuByUserId(Long userId);
}
